﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orange.Logistics.Models;
using System.Data.SqlClient;
using System.Data;

namespace Orange.Logistics.Services {
    public interface IStockDetailService : IBaseService<StockDetail> {
        IQueryable<StockDetailList> GetDetailList(int pageIndex, int pageSize, string where,
            string sort, bool asc, out int count);
    }

    public class StockDetailService : BaseService<StockDetail>, IStockDetailService {
        public IQueryable<StockDetailList> GetDetailList(int pageIndex, int pageSize, string where,
            string sort, bool asc, out int count) {
            var totalcnt = new SqlParameter {
                ParameterName = "@totalcnt",
                SqlDbType = SqlDbType.Int,
                Direction = ParameterDirection.Output
            };
            SqlParameter[] sqlParams = new SqlParameter[] { 
                new SqlParameter{ ParameterName="@pageno",Value=pageIndex},
                new SqlParameter{ ParameterName="@pagesize",Value=pageSize},
                new SqlParameter{ ParameterName="@cnd",Value=where},
                new SqlParameter{ ParameterName="@orderby",Value=sort},
                totalcnt
            };
            var list = db.Database
                .SqlQuery<StockDetailList>("sp_pagedList_group_stock_detail @pageno,@pagesize,@cnd,@orderby,@totalcnt out",
                                            sqlParams
                                         ).AsQueryable();
            count = (int)totalcnt.Value;
            return list;
        }


    }
}
